package com.xunyin;

import com.binarywang.spring.starter.wxjava.miniapp.config.WxMaAutoConfiguration;
import com.xunyin.common.websocket.MyWebScoket;
import com.xunyin.nettyV.BootNettyMqttServerThread;
import com.xunyin.utils.SpringContextHolder;
import org.java_websocket.WebSocketImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author admin
 * @date 2022/9/8
 */
@EnableAsync
@EnableTransactionManagement
@EnableCaching
@MapperScan(basePackages = {"com.xunyin.modules.*.service.mapper", "com.xunyin.config"})
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, WxMaAutoConfiguration.class})
public class ApiRun implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(ApiRun.class, args);

        // 启动  1883
        //new BootNettyServer().startup();

        System.out.println("\n共享空间系统移动端API启动成功 \n官网：https://www.toentn.com 提供技术支持ﾞ  \n");
    }

    @Override
    public void run(String... args) throws Exception {
        // 启动  1883
        int port = 1883;
        BootNettyMqttServerThread bootNettyMqttServerThread = new BootNettyMqttServerThread(port);
        bootNettyMqttServerThread.start();
        startWebsocketInstantMsg();
    }

    @Bean
    public SpringContextHolder springContextHolder() {
        return new SpringContextHolder();
    }

    /**
     * 启动websocket
     */
    public void startWebsocketInstantMsg() {
        WebSocketImpl.DEBUG = false;
        MyWebScoket s;
        s = new MyWebScoket(8888);
        s.start();
        System.out.println("websocket启动成功");
    }
}
